def output(a, n):
    for i in range(1, n+1):
        print(' '.join(map(str, a[i][1:])))


n, m = map(int, input().split())

#index start from 1
a = [[0] * (m+1) for _ in range(n + 1)]
sum = [[0] * (m+1) for _ in range(n + 1)]

#create a 2-dim list
for i in range(1, n+1):
    a[i] = [0] + list(map(int, input().split()))
output(a, n)

for i in range(1, n+1):
    for j in range(1, m+1):
        sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j]
output(sum,n)